package com.hp.attendance.serlvet.menu;

import com.hp.attendance.entity.Menu;
import com.hp.attendance.service.MenuService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/updPreMenu")
public class MenuPreUpdServlet extends HttpServlet {
    private MenuService menuService = new MenuService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            String id = req.getParameter("id");
            Menu menu = menuService.getMenu(Integer.parseInt(id));
            List<Menu> list = menuService.getList();
            req.setAttribute("menu",menu);
            req.setAttribute("list",list);
            req.getRequestDispatcher("pages/menu_update.jsp").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
